# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=gopt
pkgver=10.0
pkgrel=0
pkgdesc="C library for parsing POSIX and GNU style command line arguments"
url="http://www.purposeful.co.uk/software/gopt/"
arch="all"
license="TFL"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.xz::https://www.purposeful.co.uk/gopt/gopt-$pkgver.txz"

_soname="libgopt.so.${pkgver%.*}"

build() {

	$CC $CFLAGS -fPIC -pedantic -Wall -c *.c

	# Build shared lib.
	$CC $LDFLAGS -shared -Wl,-soname,$_soname -o $_soname *.o

	# Build static lib.
	ar rc libgopt.a *.o
	ranlib libgopt.a

	# Build testing example.
	$CC $CFLAGS $LDFLAGS -L. gopt-usage.c -o gopt-usage -lgopt
}

check() {
	LD_LIBRARY_PATH=. ./gopt-usage --version
}

package() {
	install -D -m 755 $_soname -t "$pkgdir"/usr/lib/
	ln -s $_soname "$pkgdir"/usr/lib/${_soname%.*}

	install -D -m 644 libgopt.a -t "$pkgdir"/usr/lib/
	install -D -m 644 gopt.h -t "$pkgdir"/usr/include/
}

sha512sums="
4618a23864d65fd12ec515c6d28d7a496c6fea0474c09fdab211d2ffed02ba33383ebc7591f194b56e1f75ab0d0678d9d336a1b7ffdc4e49edd00bb848c59669  gopt-10.0.tar.xz
"
